#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

import mrget
import subprocess
import mirrors.plugin


def main():
    id = mirrors.plugin.params["id"]
    dataDir = mirrors.plugin.params["storage-file"]["data-directory"]

    def filterFunc(x):
        return x["protocol"] == "rsync" and x["role"] != "local-mirror"

    if id == "centos":
        rsyncSource = mrget.target_urls("mirror://centos", filter_key=filterFunc)[0]
    elif id == "centos-altarch":
        rsyncSource = mrget.target_urls("mirror://centos-altarch", filter_key=filterFunc)[0]
    elif id == "centos-vault":
        rsyncSource = mrget.target_urls("mirror://centos-vault", filter_key=filterFunc)[0]
    else:
        assert False

    subprocess.run(["rsync", "-v", "-a", "-z", "-H", "--delete", rsyncSource, dataDir])


if __name__ == "__main__":
    main()
